/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.minierp.bean.AccountBalanceBean;
import com.minierp.bean.BankAccountBean;
import com.minierp.bean.UserBean;
import com.minierp.bean.UserStatus;
import com.minierp.dao.AdjustBillDao;
import com.minierp.dao.BankAccountBalanceDao;
import com.minierp.dao.BankAccountDao;
import com.minierp.dao.BankAccountDetailDao;
import com.minierp.dao.BusinessBillDao;
import com.minierp.dao.CooperBillDao;
import com.minierp.dao.FeeBillDao;
import com.minierp.dao.FeeTypeDao;
import com.minierp.dao.IncomeBillDao;
import com.minierp.dao.IncomeTypeDao;
import com.minierp.dao.OutBillDao;
import com.minierp.dao.PayBillDao;
import com.minierp.dao.PurchaseBillDao;
import com.minierp.dao.ReceiveBillDao;
import com.minierp.dao.TallySetDao;
import com.minierp.err.PermissionDennyException;
import com.minierp.helper.EncCommonHelper;
import com.minierp.helper.EncInterceptorHelper;
import com.minierp.helper.PageHelper;
import com.minierp.model.BankAccount;
import com.minierp.model.BankAccountBalance;
import com.minierp.model.BankAccountDetail;
import com.minierp.model.EnterpriseInfo;
import com.minierp.model.TallySet;
import com.minierp.view.AccountBalanceListExcelView;
import com.minierp.view.AccountDetailListExcelView;
import com.minierp.view.ProfitCountExcelView;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class BankAccountMACtr extends MultiActionController {
	private BankAccountDao bankAccountDao;
	private BankAccountBalanceDao bankAccountBalanceDao;
	private BankAccountDetailDao bankAccountDetailDao;
	private IncomeTypeDao incomeTypeDao;
	private FeeTypeDao feeTypeDao;
	private AdjustBillDao adjustBillDao;
	private BusinessBillDao businessBillDao;
	private CooperBillDao cooperBillDao;
	private OutBillDao outBillDao;
	private FeeBillDao feeBillDao;
	private IncomeBillDao incomeBillDao;
	private TallySetDao tallySetDao;
	private ReceiveBillDao receiveBillDao;
	private PayBillDao payBillDao;
	private PurchaseBillDao purchaseBillDao;
	private String listView;
	private String balanceListView;
	private String detailListView;
	private String detailPrintView;
	private String profitSearchView;
	private String profitSearchPrintView;
	private String profitCountView;
	private String profitCountPrintView;
	private String logListView;

	public String getLogListView() {
		return this.logListView;
	}

	public void setLogListView(String logListView) {
		this.logListView = logListView;
	}

	public PurchaseBillDao getPurchaseBillDao() {
		return this.purchaseBillDao;
	}

	public void setPurchaseBillDao(PurchaseBillDao purchaseBillDao) {
		this.purchaseBillDao = purchaseBillDao;
	}

	public String getProfitCountPrintView() {
		return this.profitCountPrintView;
	}

	public void setProfitCountPrintView(String profitCountPrintView) {
		this.profitCountPrintView = profitCountPrintView;
	}

	public FeeBillDao getFeeBillDao() {
		return this.feeBillDao;
	}

	public void setFeeBillDao(FeeBillDao feeBillDao) {
		this.feeBillDao = feeBillDao;
	}

	public IncomeBillDao getIncomeBillDao() {
		return this.incomeBillDao;
	}

	public void setIncomeBillDao(IncomeBillDao incomeBillDao) {
		this.incomeBillDao = incomeBillDao;
	}

	public String getProfitCountView() {
		return this.profitCountView;
	}

	public void setProfitCountView(String profitCountView) {
		this.profitCountView = profitCountView;
	}

	public BusinessBillDao getBusinessBillDao() {
		return this.businessBillDao;
	}

	public void setBusinessBillDao(BusinessBillDao businessBillDao) {
		this.businessBillDao = businessBillDao;
	}

	public CooperBillDao getCooperBillDao() {
		return this.cooperBillDao;
	}

	public void setCooperBillDao(CooperBillDao cooperBillDao) {
		this.cooperBillDao = cooperBillDao;
	}

	public OutBillDao getOutBillDao() {
		return this.outBillDao;
	}

	public void setOutBillDao(OutBillDao outBillDao) {
		this.outBillDao = outBillDao;
	}

	public AdjustBillDao getAdjustBillDao() {
		return this.adjustBillDao;
	}

	public void setAdjustBillDao(AdjustBillDao adjustBillDao) {
		this.adjustBillDao = adjustBillDao;
	}

	public String getProfitSearchPrintView() {
		return this.profitSearchPrintView;
	}

	public void setProfitSearchPrintView(String profitSearchPrintView) {
		this.profitSearchPrintView = profitSearchPrintView;
	}

	public ModelAndView handleList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "BANK_ACCO")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			ModelAndView mv = new ModelAndView(this.listView);
			List list = this.bankAccountDao.getList("", "Y");
			List tsList = this.tallySetDao.getList(false);
			ArrayList arr = new ArrayList();

			for (int i = 0; i < list.size(); ++i) {
				BankAccountBean bean = new BankAccountBean();
				bean.setBankAccount((BankAccount) list.get(i));
				bean.setTallySetName(EncCommonHelper.getSimpleObjectName(
						tsList, bean.getBankAccount().getTallySetId()));
				arr.add(bean);
			}

			mv.addObject("bankAccountList", arr);
			return mv;
		}
	}

	public ModelAndView handleDelete(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String returnUrl = request.getParameter("from_url");
		ModelAndView mv = new ModelAndView("redirect:" + returnUrl);
		if (!EncCommonHelper.checkPrivilege(request, "BANK_ACCO")) {
			throw new Exception("Permission deny!");
		} else {
			String id = request.getParameter("id");
			BankAccount b = (BankAccount) this.bankAccountDao.get(
					BankAccount.class, Long.parseLong(id));
			if (b != null) {
				if (b.getCurrentCost().compareTo(new BigDecimal(0)) != 0) {
					EncCommonHelper.setAlertMessage(request, "余额不为0，不能删除！");
				} else {
					b.setEnabled("N");
					this.bankAccountDao.update(b);
					EncCommonHelper.setAlertMessage(request, "删除成功！");
				}
			}

			return mv;
		}
	}

	public ModelAndView handlePause(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String retUrl = request.getParameter("from_url");
		String flag = request.getParameter("flag");
		String id = request.getParameter("id");
		ModelAndView mv = new ModelAndView("redirect:" + retUrl);
		BankAccount b = (BankAccount) this.bankAccountDao.get(
				BankAccount.class, Long.parseLong(id));
		if (b != null) {
			b.setStatus(flag);
			this.bankAccountDao.update(b);
		}

		EncCommonHelper.setAlertMessage(request, "设置成功！");
		return mv;
	}

	public ModelAndView handleBalanceList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "BANK_COST")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
			String contentType = request.getParameter("content_type");
			String startDateStr = request.getParameter("start_date");
			String endDateStr = request.getParameter("end_date");
			String tsId = request.getParameter("ts_id");
			String searchKey = request.getParameter("search_key");
			String isTmp = request.getParameter("is_tmp");
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat shortSf = new SimpleDateFormat("yyyy-MM");
			Date startDate;
			if (startDateStr == null || startDateStr.equals("")) {
				startDate = new Date();
				startDateStr = sf.format(startDate);
				endDateStr = sf.format(startDate);
				tsId = String.valueOf(ub.getUser().getDfTsId());
			}

			startDate = null;
			Date monthStartDate = null;
			if (startDateStr != null && !startDateStr.equals("")) {
				startDate = sf.parse(startDateStr);
				monthStartDate = sf.parse(shortSf.format(startDate) + "-01");
			}

			Date endDate = null;
			if (endDateStr != null && !endDateStr.equals("")) {
				endDate = sf.parse(EncCommonHelper.getNextDateStr(endDateStr,
						"yyyy-MM-dd"));
			}

			List bankAccountList = PageHelper.parseBaList(
					this.bankAccountDao.getList("Y", "Y"), ent, ub, 0L, 0L);
			List costList = this.bankAccountDetailDao.getBankAccountCost(
					startDate, endDate);
			ArrayList arr = new ArrayList();
			AccountBalanceBean totalBean = new AccountBalanceBean();
			String baIdStr = "";

			for (int map = 0; map < bankAccountList.size(); ++map) {
				BankAccount v = (BankAccount) bankAccountList.get(map);
				boolean baOk = true;
				if (searchKey != null && !searchKey.equals("")
						&& v.getAccountName().indexOf(searchKey) == -1
						&& v.getBankName().indexOf(searchKey) == -1) {
					baOk = false;
				}

				if (baOk && tsId != null && !tsId.equals("")
						&& !tsId.equals("0")
						&& v.getTallySetId() != Long.parseLong(tsId)) {
					baOk = false;
				}

				if (baOk && isTmp != null && !isTmp.equals("")
						&& !isTmp.equals(v.getIsTmp())) {
					baOk = false;
				}

				if (baOk) {
					if (!baIdStr.equals("")) {
						baIdStr = baIdStr + ";";
					}

					baIdStr = baIdStr + v.getId();
					BigDecimal monthInitCost = new BigDecimal(0);
					BankAccountBalance bab = this.bankAccountBalanceDao
							.getPreviousBalance(v.getId(), startDate);
					if (bab != null) {
						monthInitCost = bab.getCost();
					}

					BigDecimal preCost = this.bankAccountDetailDao.getCost(
							v.getId(), monthStartDate, startDate);
					BigDecimal recCost = new BigDecimal(0);
					BigDecimal expCost = new BigDecimal(0);
					BigDecimal busCost = new BigDecimal(0);
					BigDecimal incomeCost = new BigDecimal(0);
					BigDecimal loanInCost = new BigDecimal(0);
					BigDecimal tranInCost = new BigDecimal(0);
					BigDecimal purCost = new BigDecimal(0);
					BigDecimal cooCost = new BigDecimal(0);
					BigDecimal feeCost = new BigDecimal(0);
					BigDecimal loanOutCost = new BigDecimal(0);
					BigDecimal tranOutCost = new BigDecimal(0);

					for (int startCost = 0; startCost < costList.size(); ++startCost) {
						Object[] endCost = (Object[]) costList.get(startCost);
						long b = Long.parseLong(endCost[0].toString());
						String financeType = endCost[1].toString();
						BigDecimal cost = new BigDecimal(endCost[2].toString());
						if (v.getId() == b) {
							if (financeType.equals("BUSINESS")) {
								busCost = busCost.add(cost);
								recCost = recCost.add(cost);
							} else if (financeType.equals("INCOME")) {
								incomeCost = incomeCost.add(cost);
								recCost = recCost.add(cost);
							} else if (financeType.equals("LOAN_IN")) {
								loanInCost = loanInCost.add(cost);
								recCost = recCost.add(cost);
							} else if (financeType.equals("TRANSFER_IN")) {
								tranInCost = tranInCost.add(cost);
								recCost = recCost.add(cost);
							} else if (financeType.equals("PURCHASE")) {
								purCost = purCost.add(cost);
								expCost = expCost.add(cost);
							} else if (financeType.equals("COOPER")) {
								cooCost = cooCost.add(cost);
								expCost = expCost.add(cost);
							} else if (financeType.equals("FEE")) {
								feeCost = feeCost.add(cost);
								expCost = expCost.add(cost);
							} else if (financeType.equals("LOAN_OUT")) {
								loanOutCost = loanOutCost.add(cost);
								expCost = expCost.add(cost);
							} else {
								if (!financeType.equals("TRANSFER_OUT")) {
									throw new Exception("finance type "
											+ financeType + " not supported!");
								}

								tranOutCost = tranOutCost.add(cost);
								expCost = expCost.add(cost);
							}
						}
					}

					BigDecimal arg46 = monthInitCost.add(preCost);
					BigDecimal arg47 = arg46.add(recCost).subtract(expCost);
					AccountBalanceBean arg48 = new AccountBalanceBean();
					arg48.setAccountId(v.getId());
					String bankName = v.getBankName();
					if (v.getAccountName() != null
							&& !v.getAccountName().equals("")) {
						bankName = bankName + "(" + v.getAccountName() + ")";
					}

					arg48.setAccountName(bankName);
					arg48.setEndCost(arg47);
					arg48.setExpCost(expCost);
					arg48.setRecCost(recCost);
					arg48.setStartCost(arg46);
					arg48.setBusCost(busCost);
					arg48.setIncomeCost(incomeCost);
					arg48.setLoanInCost(loanInCost);
					arg48.setTranInCost(tranInCost);
					arg48.setPurCost(purCost);
					arg48.setCooCost(cooCost);
					arg48.setFeeCost(feeCost);
					arg48.setLoanOutCost(loanOutCost);
					arg48.setTranOutCost(tranOutCost);
					arr.add(arg48);
					totalBean.setEndCost(totalBean.getEndCost().add(arg47));
					totalBean.setExpCost(totalBean.getExpCost().add(expCost));
					totalBean.setRecCost(totalBean.getRecCost().add(recCost));
					totalBean.setStartCost(totalBean.getStartCost().add(arg46));
					totalBean.setBusCost(totalBean.getBusCost().add(busCost));
					totalBean.setIncomeCost(totalBean.getIncomeCost().add(
							incomeCost));
					totalBean.setLoanInCost(totalBean.getLoanInCost().add(
							loanInCost));
					totalBean.setTranInCost(totalBean.getTranInCost().add(
							tranInCost));
					totalBean.setPurCost(totalBean.getPurCost().add(purCost));
					totalBean.setCooCost(totalBean.getCooCost().add(cooCost));
					totalBean.setFeeCost(totalBean.getFeeCost().add(feeCost));
					totalBean.setLoanOutCost(totalBean.getLoanOutCost().add(
							loanOutCost));
					totalBean.setTranOutCost(totalBean.getTranOutCost().add(
							tranOutCost));
				}
			}

			if (contentType != null && contentType.equals("EXCEL")) {
				HashMap arg44 = new HashMap();
				arg44.put("list", arr);
				arg44.put("totalBean", totalBean);
				arg44.put("startDate", startDateStr);
				arg44.put("endDate", endDateStr);
				AccountBalanceListExcelView arg45 = new AccountBalanceListExcelView();
				return new ModelAndView(arg45, arg44);
			} else {
				ModelAndView mv = new ModelAndView(this.balanceListView);
				mv.addObject("list", arr);
				mv.addObject("totalBean", totalBean);
				mv.addObject("startDate", startDateStr);
				mv.addObject("endDate", endDateStr);
				mv.addObject("tsId", tsId);
				mv.addObject("isTmp", isTmp);
				mv.addObject("searchKey", searchKey);
				mv.addObject("tsList",
						PageHelper.getTallySetList(this.tallySetDao, ub));
				mv.addObject("baIdStr", baIdStr);
				return mv;
			}
		}
	}

	public ModelAndView handleDetailList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String contentType = request.getParameter("content_type");
		String baId = request.getParameter("ba_id");
		String financeType = request.getParameter("finance_type");
		String rcType = request.getParameter("rc_type");
		String startDateStr = request.getParameter("start_date");
		String endDateStr = request.getParameter("end_date");
		String listType = request.getParameter("list_type");
		if (listType == null || listType.equals("")) {
			listType = "BILL";
		}

		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		Date startDate = null;
		if (startDateStr != null && !startDateStr.equals("")) {
			startDate = sf.parse(startDateStr);
		}

		Date endDate = null;
		if (endDateStr != null && !endDateStr.equals("")) {
			endDate = sf.parse(EncCommonHelper.getNextDateStr(endDateStr,
					"yyyy-MM-dd"));
		}

		BigDecimal rcostTotal = new BigDecimal(0);
		BigDecimal pcostTotal = new BigDecimal(0);
		String baName = "";
		Object list = new ArrayList();
		if (baId != null && !baId.equals("")) {
			String[] map = baId.split(";");
			BankAccount v = (BankAccount) this.bankAccountBalanceDao.get(
					BankAccount.class, Long.parseLong(map[0]));
			baName = v.getBankName();
			if (map.length > 1) {
				baName = baName + "...";
			}

			list = this.bankAccountDetailDao.getList(map, startDate, endDate,
					financeType, rcType, listType);
			List costList = this.bankAccountDetailDao.getCost(map, startDate,
					endDate, financeType, rcType, listType);

			for (int i = 0; i < costList.size(); ++i) {
				Object[] objs = (Object[]) costList.get(i);
				if (objs[0] != null) {
					if (((String) objs[0]).equals("R")) {
						rcostTotal = (BigDecimal) objs[1];
					} else {
						pcostTotal = (BigDecimal) objs[1];
					}
				}
			}
		}

		if (contentType != null && contentType.equals("EXCEL")) {
			HashMap arg22 = new HashMap();
			arg22.put("list", list);
			arg22.put("financeType", financeType);
			arg22.put("rcType", rcType);
			arg22.put("baName", baName);
			arg22.put("baList", this.bankAccountDao.getList("", ""));
			arg22.put("startDate", startDateStr);
			arg22.put("endDate", endDateStr);
			arg22.put("listType", listType);
			arg22.put("rcostTotal", rcostTotal);
			arg22.put("pcostTotal", pcostTotal);
			AccountDetailListExcelView arg23 = new AccountDetailListExcelView();
			return new ModelAndView(arg23, arg22);
		} else {
			ModelAndView mv;
			if (contentType != null && contentType.equals("PRINT")) {
				mv = new ModelAndView(this.detailPrintView);
			} else {
				mv = new ModelAndView(this.detailListView);
			}

			mv.addObject("list", list);
			mv.addObject("financeType", financeType);
			mv.addObject("rcType", rcType);
			mv.addObject("baId", baId);
			mv.addObject("startDate", startDateStr);
			mv.addObject("endDate", endDateStr);
			mv.addObject("listType", listType);
			mv.addObject("baName", baName);
			mv.addObject("rcostTotal", rcostTotal);
			mv.addObject("pcostTotal", pcostTotal);
			mv.addObject("baList", this.bankAccountDao.getList("", ""));
			return mv;
		}
	}

	public ModelAndView handleLogList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView(this.logListView);
		String baId = request.getParameter("ba_id");
		String startDateStr = request.getParameter("start_date");
		String endDateStr = request.getParameter("end_date");
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		Date startDate = null;
		if (startDateStr != null && !startDateStr.equals("")) {
			startDate = sf.parse(startDateStr);
		}

		Date endDate = null;
		if (endDateStr != null && !endDateStr.equals("")) {
			endDate = sf.parse(EncCommonHelper.getNextDateStr(endDateStr,
					"yyyy-MM-dd"));
		}

		Object list = new ArrayList();
		if (baId != null && !baId.equals("")) {
			String[] ent = baId.split(";");
			list = this.bankAccountDetailDao.getList(ent, startDate, endDate,
					"", "", "LOG");
		}

		EnterpriseInfo ent1 = EncCommonHelper.getEnterpriseInfo(request);
		UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
		List baList = PageHelper.parseBaList(
				this.bankAccountDao.getList("Y", "Y"), ent1, ub, 0L, 0L);
		mv.addObject("baList", baList);
		mv.addObject("list", list);
		mv.addObject("startDate", startDateStr);
		mv.addObject("endDate", endDateStr);
		mv.addObject("baId", baId);
		return mv;
	}

	public ModelAndView handleProfitSearch(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "PROF_SEAR")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			String type = request.getParameter("type");
			String tallySetId = request.getParameter("ts_id");
			String startDateStr = request.getParameter("start_date");
			String endDateStr = request.getParameter("end_date");
			String contentType = request.getParameter("content_type");
			ModelAndView mv;
			if (contentType != null && contentType.equals("PRINT")) {
				mv = new ModelAndView(this.profitSearchPrintView);
			} else {
				mv = new ModelAndView(this.profitSearchView);
			}

			UserBean ub = EncCommonHelper.getCurrentUserAccount(request);
			List tallySetList = PageHelper
					.getTallySetList(this.tallySetDao, ub);
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat shortSf = new SimpleDateFormat("yyyy-MM");
			Date now = new Date();
			if (type == null || type.equals("")) {
				type = "BILL";
				startDateStr = shortSf.format(now) + "-01";
				endDateStr = sf.format(now);
				tallySetId = String.valueOf(ub.getUser().getDfTsId());
			}

			Date startDate = null;
			if (startDateStr != null && !startDateStr.equals("")) {
				startDate = sf.parse(startDateStr);
			}

			Date endDate = null;
			if (endDateStr != null && !endDateStr.equals("")) {
				endDate = sf.parse(EncCommonHelper.getNextDateStr(endDateStr,
						"yyyy-MM-dd"));
			}

			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				Date objs = EncCommonHelper.getEarlDataDate(request);
				if (objs.after(startDate)) {
					startDate = objs;
					startDateStr = sf.format(objs);
				}
			}

			Object[] newObjs = (Object[]) null;
			List bankAccountList = this.bankAccountDao.getList("", "");
			BigDecimal inAdj = new BigDecimal(0);
			BigDecimal outAdj = new BigDecimal(0);
			BigDecimal incCost;
			int inTotal;
			Object[] arg38;
			if (!type.equals("REC")) {
				List salTotal = this.adjustBillDao.getCost(
						Long.parseLong(tallySetId), ub, startDate, endDate);
				String incList = "";

				for (inTotal = 0; inTotal < salTotal.size(); ++inTotal) {
					arg38 = (Object[]) salTotal.get(inTotal);
					incList = arg38[1].toString();
					incCost = new BigDecimal(arg38[0].toString());
					if (incList.equals("COLLECT_ABATE")) {
						inAdj = inAdj.subtract(incCost);
					} else if (incList.equals("COLLECT_ADD")) {
						inAdj = inAdj.add(incCost);
					} else if (incList.equals("COO_ABATE")) {
						outAdj = outAdj.subtract(incCost);
					} else if (incList.equals("COO_ADD")) {
						outAdj = outAdj.add(incCost);
					} else if (incList.equals("PAY_ABATE")) {
						outAdj = outAdj.subtract(incCost);
					} else if (incList.equals("PAY_ADD")) {
						outAdj = outAdj.add(incCost);
					} else if (incList.equals("PUR_BACK_ABATE")) {
						outAdj = outAdj.add(incCost);
					} else {
						if (!incList.equals("PUR_BACK_ADD")) {
							throw new Exception(incList + " not supported!");
						}

						outAdj = outAdj.subtract(incCost);
					}
				}
			}

			BigDecimal arg39 = new BigDecimal(0);
			String bankAccountName;
			List arg40;
			if (type.equals("REC")) {
				arg40 = this.businessBillDao.getBaImprest(
						Long.parseLong(tallySetId), ub, startDate, endDate);
				HashMap arg41 = new HashMap();

				for (inTotal = 0; inTotal < arg40.size(); ++inTotal) {
					arg38 = (Object[]) arg40.get(inTotal);
					newObjs = new Object[3];
					arg39 = arg39.add(new BigDecimal(arg38[0].toString()));
					bankAccountName = EncCommonHelper.getSimpleObjectName(
							bankAccountList,
							Long.parseLong(arg38[1].toString()));
					newObjs[0] = arg38[0];
					newObjs[1] = arg38[1];
					newObjs[2] = bankAccountName;
					arg41.put(arg38[1].toString(), newObjs);
				}

				List arg42 = this.receiveBillDao.getBaCost(
						Long.parseLong(tallySetId), ub, startDate, endDate);

				for (int mateTotal = 0; mateTotal < arg42.size(); ++mateTotal) {
					arg38 = (Object[]) arg42.get(mateTotal);
					arg39 = arg39.add(new BigDecimal(arg38[0].toString()));
					if (arg41.containsKey(arg38[1].toString())) {
						newObjs = (Object[]) arg41.get(arg38[1].toString());
						newObjs[0] = ((BigDecimal) newObjs[0])
								.add((BigDecimal) arg38[0]);
					} else {
						newObjs = new Object[3];
						bankAccountName = EncCommonHelper.getSimpleObjectName(
								bankAccountList,
								Long.parseLong(arg38[1].toString()));
						newObjs[0] = arg38[0];
						newObjs[1] = arg38[1];
						newObjs[2] = bankAccountName;
					}

					arg41.put(arg38[1].toString(), newObjs);
				}

				mv.addObject("salList", arg41.values());
			} else {
				arg39 = this.businessBillDao.getCost(
						Long.parseLong(tallySetId), ub, startDate, endDate);
			}

			arg40 = this.incomeBillDao.getTypeCost(Long.parseLong(tallySetId),
					ub, startDate, endDate);
			incCost = new BigDecimal(0);

			for (inTotal = 0; inTotal < arg40.size(); ++inTotal) {
				arg38 = (Object[]) arg40.get(inTotal);
				incCost = incCost.add((BigDecimal) arg38[0]);
			}

			BigDecimal arg44 = arg39.add(incCost).add(inAdj);
			BigDecimal arg43 = new BigDecimal(0);
			BigDecimal zero = new BigDecimal(0);
			String proTotal;
			int arg49;
			if (type.equals("REC")) {
				List cooTotal = this.purchaseBillDao.getBaImprest(
						Long.parseLong(tallySetId), ub, startDate, endDate);
				HashMap feeList = new HashMap();

				for (int feeCost = 0; feeCost < cooTotal.size(); ++feeCost) {
					arg38 = (Object[]) cooTotal.get(feeCost);
					String outTotal = (String) arg38[2];
					newObjs = new Object[4];
					if (outTotal.equals("BUY")) {
						arg43 = arg43.add((BigDecimal) arg38[0]);
						newObjs[0] = arg38[0];
					} else {
						arg43 = arg43.subtract((BigDecimal) arg38[0]);
						newObjs[0] = zero.subtract((BigDecimal) arg38[0]);
					}

					bankAccountName = EncCommonHelper.getSimpleObjectName(
							bankAccountList,
							Long.parseLong(arg38[1].toString()));
					newObjs[1] = arg38[1];
					newObjs[2] = bankAccountName;
					proTotal = "0";
					if (arg44.compareTo(zero) != 0) {
						proTotal = ((BigDecimal) newObjs[0])
								.multiply(new BigDecimal(100))
								.divide(arg44, 2, 4).toString();
					}

					newObjs[3] = proTotal;
					feeList.put(arg38[1].toString(), newObjs);
				}

				List arg47 = this.payBillDao.getBaCost(
						Long.parseLong(tallySetId), ub, startDate, endDate,
						"PURCHASE");

				for (arg49 = 0; arg49 < arg47.size(); ++arg49) {
					arg38 = (Object[]) arg47.get(arg49);
					arg43 = arg43.add((BigDecimal) arg38[0]);
					if (feeList.containsKey(arg38[1].toString())) {
						newObjs = (Object[]) feeList.get(arg38[1].toString());
						newObjs[0] = ((BigDecimal) newObjs[0])
								.add((BigDecimal) arg38[0]);
					} else {
						newObjs = new Object[4];
						bankAccountName = EncCommonHelper.getSimpleObjectName(
								bankAccountList,
								Long.parseLong(arg38[1].toString()));
						newObjs[0] = arg38[0];
						newObjs[1] = arg38[1];
						newObjs[2] = bankAccountName;
					}

					proTotal = "0";
					if (arg44.compareTo(new BigDecimal(0)) != 0) {
						proTotal = ((BigDecimal) newObjs[0])
								.multiply(new BigDecimal(100))
								.divide(arg44, 2, 4).toString();
					}

					newObjs[3] = proTotal;
					feeList.put(arg38[1].toString(), newObjs);
				}

				mv.addObject("purList", feeList.values());
			} else {
				arg43 = this.outBillDao.getCost(Long.parseLong(tallySetId), ub,
						startDate, endDate);
			}

			BigDecimal arg45 = new BigDecimal(0);
			List arg46;
			if (type.equals("REC")) {
				arg46 = this.cooperBillDao.getBaImprest(
						Long.parseLong(tallySetId), ub, startDate, endDate);
				HashMap arg48 = new HashMap();

				for (arg49 = 0; arg49 < arg46.size(); ++arg49) {
					arg38 = (Object[]) arg46.get(arg49);
					newObjs = new Object[4];
					arg45 = arg45.add((BigDecimal) arg38[0]);
					bankAccountName = EncCommonHelper.getSimpleObjectName(
							bankAccountList,
							Long.parseLong(arg38[1].toString()));
					newObjs[0] = arg38[0];
					newObjs[1] = arg38[1];
					newObjs[2] = bankAccountName;
					proTotal = "0";
					if (arg44.compareTo(new BigDecimal(0)) != 0) {
						proTotal = ((BigDecimal) newObjs[0])
								.multiply(new BigDecimal(100))
								.divide(arg44, 2, 4).toString();
					}

					newObjs[3] = proTotal;
					arg48.put(arg38[1].toString(), newObjs);
				}

				List arg51 = this.payBillDao.getBaCost(
						Long.parseLong(tallySetId), ub, startDate, endDate,
						"COOPER");

				for (int arg54 = 0; arg54 < arg51.size(); ++arg54) {
					arg38 = (Object[]) arg51.get(arg54);
					arg45 = arg45.add((BigDecimal) arg38[0]);
					if (arg48.containsKey(arg38[1].toString())) {
						newObjs = (Object[]) arg48.get(arg38[1].toString());
						newObjs[0] = ((BigDecimal) newObjs[0])
								.add((BigDecimal) arg38[0]);
					} else {
						newObjs = new Object[4];
						bankAccountName = EncCommonHelper.getSimpleObjectName(
								bankAccountList,
								Long.parseLong(arg38[1].toString()));
						newObjs[0] = arg38[0];
						newObjs[1] = arg38[1];
						newObjs[2] = bankAccountName;
					}

					String proPercent = "0";
					if (arg44.compareTo(new BigDecimal(0)) != 0) {
						proPercent = ((BigDecimal) newObjs[0])
								.multiply(new BigDecimal(100))
								.divide(arg44, 2, 4).toString();
					}

					newObjs[3] = proPercent;
					arg48.put(arg38[1].toString(), newObjs);
				}

				mv.addObject("cooList", arg48.values());
			} else {
				arg45 = this.cooperBillDao.getCost(Long.parseLong(tallySetId),
						ub, startDate, endDate);
			}

			arg46 = this.feeBillDao.getTypeCost(Long.parseLong(tallySetId), ub,
					startDate, endDate);
			BigDecimal arg50 = new BigDecimal(0);

			for (arg49 = 0; arg49 < arg46.size(); ++arg49) {
				arg38 = (Object[]) arg46.get(arg49);
				arg50 = arg50.add((BigDecimal) arg38[0]);
				proTotal = "0";
				if (arg44.compareTo(new BigDecimal(0)) != 0) {
					proTotal = ((BigDecimal) arg38[0])
							.multiply(new BigDecimal(100)).divide(arg44, 2, 4)
							.toString();
				}

				arg38[3] = proTotal;
			}

			BigDecimal arg52 = arg43.add(arg45).add(arg50).add(outAdj);
			BigDecimal arg55 = arg44.subtract(arg52);
			BigDecimal arg53 = new BigDecimal(0);
			if (arg44.compareTo(new BigDecimal(0)) != 0) {
				arg53 = arg55.multiply(new BigDecimal(100)).divide(arg44, 2, 4);
			}

			String outTotalPer = "0";
			String mateTotalPer = "0";
			String cooTotalPer = "0";
			String feeTotalPer = "0";
			String outAdjPer = "0";
			if (arg44.compareTo(new BigDecimal(0)) != 0) {
				outTotalPer = arg52.multiply(new BigDecimal(100))
						.divide(arg44, 2, 4).toString();
				mateTotalPer = arg43.multiply(new BigDecimal(100))
						.divide(arg44, 2, 4).toString();
				cooTotalPer = arg45.multiply(new BigDecimal(100))
						.divide(arg44, 2, 4).toString();
				feeTotalPer = arg50.multiply(new BigDecimal(100))
						.divide(arg44, 2, 4).toString();
				outAdjPer = outAdj.multiply(new BigDecimal(100))
						.divide(arg44, 2, 4).toString();
			}

			mv.addObject("proTotal", arg55);
			mv.addObject("inTotal", arg44);
			mv.addObject("outTotal", arg52);
			mv.addObject("salTotal", arg39);
			mv.addObject("mateTotal", arg43);
			mv.addObject("inAdj", inAdj);
			mv.addObject("outAdj", outAdj);
			mv.addObject("cooTotal", arg45);
			mv.addObject("incCost", incCost);
			mv.addObject("feeCost", arg50);
			mv.addObject("incList", arg40);
			mv.addObject("feeList", arg46);
			mv.addObject("proPercent", arg53);
			mv.addObject("outTotalPer", outTotalPer);
			mv.addObject("mateTotalPer", mateTotalPer);
			mv.addObject("cooTotalPer", cooTotalPer);
			mv.addObject("feeTotalPer", feeTotalPer);
			mv.addObject("outAdjPer", outAdjPer);
			mv.addObject("startDate", startDateStr);
			mv.addObject("endDate", endDateStr);
			mv.addObject("tsId", tallySetId);
			mv.addObject("tallySetList", tallySetList);
			mv.addObject("type", type);
			return mv;
		}
	}

	public ModelAndView handleProfitCount(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "PROF_COUN")) {
			throw new PermissionDennyException("Permission Denny");
		} else {
			String year = request.getParameter("year");
			String tsId = request.getParameter("ts_id");
			Date now = new Date();
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat yearSf = new SimpleDateFormat("yyyy");
			String currentYear = yearSf.format(now);
			if (year == null || year.equals("")) {
				year = currentYear;
			}

			Date startDate = sf.parse(year + "-01-01");
			Calendar c = Calendar.getInstance();
			c.setTime(startDate);
			c.add(1, 1);
			Date endDate = c.getTime();
			if (EncCommonHelper.checkPurePrivilege(request, "NO_EARL_DATA")) {
				Date ub = EncCommonHelper.getEarlDataDate(request);
				if (ub.after(startDate)) {
					startDate = ub;
				}
			}

			UserBean arg26 = EncCommonHelper.getCurrentUserAccount(request);
			if (tsId == null || tsId.equals("")) {
				tsId = String.valueOf(arg26.getUser().getDfTsId());
			}

			ArrayList arr = new ArrayList();

			for (int totalObjs = 1; totalObjs <= 12; ++totalObjs) {
				Object[] cost = new Object[7];

				for (int busList = 0; busList < cost.length; ++busList) {
					cost[busList] = new BigDecimal(0);
				}

				arr.add(cost);
			}

			Object[] arg27 = new Object[7];

			for (int arg28 = 0; arg28 < arg27.length; ++arg28) {
				arg27[arg28] = new BigDecimal(0);
			}

			List arg30 = this.businessBillDao.getMonthCost(startDate, endDate,
					Long.parseLong(tsId), arg26, 0L, (Date) null);

			Object[] outList;
			int feeList;
			BigDecimal arg29;
			for (int incList = 1; incList <= 12; ++incList) {
				Object[] cooList = (Object[]) arr.get(incList - 1);

				for (feeList = 0; feeList < arg30.size(); ++feeList) {
					outList = (Object[]) arg30.get(feeList);
					if (incList == Integer.parseInt(outList[0].toString())) {
						arg29 = new BigDecimal(outList[1].toString());
						cooList[0] = ((BigDecimal) cooList[0]).add(arg29);
						cooList[6] = ((BigDecimal) cooList[6]).add(arg29);
						arg27[0] = ((BigDecimal) arg27[0]).add(arg29);
						arg27[6] = ((BigDecimal) arg27[6]).add(arg29);
						break;
					}
				}
			}

			List arg31 = this.incomeBillDao.getMonthCost(startDate, endDate,
					Long.parseLong(tsId), arg26);

			int adjList;
			Object[] arg36;
			for (int arg32 = 1; arg32 <= 12; ++arg32) {
				outList = (Object[]) arr.get(arg32 - 1);

				for (adjList = 0; adjList < arg31.size(); ++adjList) {
					arg36 = (Object[]) arg31.get(adjList);
					if (arg32 == Integer.parseInt(arg36[0].toString())) {
						arg29 = new BigDecimal(arg36[1].toString());
						outList[1] = ((BigDecimal) outList[1]).add(arg29);
						outList[6] = ((BigDecimal) outList[6]).add(arg29);
						arg27[1] = ((BigDecimal) arg27[1]).add(arg29);
						arg27[6] = ((BigDecimal) arg27[6]).add(arg29);
						break;
					}
				}
			}

			List arg33 = this.cooperBillDao.getMonthCost(startDate, endDate,
					Long.parseLong(tsId), arg26, 0L, (Date) null);

			int contentType;
			Object[] arg37;
			for (int arg34 = 1; arg34 <= 12; ++arg34) {
				arg36 = (Object[]) arr.get(arg34 - 1);

				for (contentType = 0; contentType < arg33.size(); ++contentType) {
					arg37 = (Object[]) arg33.get(contentType);
					if (arg34 == Integer.parseInt(arg37[0].toString())) {
						arg29 = new BigDecimal(arg37[1].toString());
						arg36[2] = ((BigDecimal) arg36[2]).add(arg29);
						arg36[6] = ((BigDecimal) arg36[6]).subtract(arg29);
						arg27[2] = ((BigDecimal) arg27[2]).add(arg29);
						arg27[6] = ((BigDecimal) arg27[6]).subtract(arg29);
						break;
					}
				}
			}

			List arg35 = this.outBillDao.getMonthCost(startDate, endDate,
					Long.parseLong(tsId), arg26, (Date) null);

			Object[] arg39;
			for (feeList = 1; feeList <= 12; ++feeList) {
				arg37 = (Object[]) arr.get(feeList - 1);

				for (int mv = 0; mv < arg35.size(); ++mv) {
					arg39 = (Object[]) arg35.get(mv);
					if (feeList == Integer.parseInt(arg39[0].toString())) {
						arg29 = new BigDecimal(arg39[1].toString());
						arg37[3] = ((BigDecimal) arg37[3]).add(arg29);
						arg37[6] = ((BigDecimal) arg37[6]).subtract(arg29);
						arg27[3] = ((BigDecimal) arg27[3]).add(arg29);
						arg27[6] = ((BigDecimal) arg27[6]).subtract(arg29);
						break;
					}
				}
			}

			List arg38 = this.feeBillDao.getMonthCost(startDate, endDate,
					Long.parseLong(tsId), arg26);

			Object[] arg41;
			for (adjList = 1; adjList <= 12; ++adjList) {
				arg39 = (Object[]) arr.get(adjList - 1);

				for (int v = 0; v < arg38.size(); ++v) {
					arg41 = (Object[]) arg38.get(v);
					if (adjList == Integer.parseInt(arg41[0].toString())) {
						arg29 = new BigDecimal(arg41[1].toString());
						arg39[4] = ((BigDecimal) arg39[4]).add(arg29);
						arg39[6] = ((BigDecimal) arg39[6]).subtract(arg29);
						arg27[4] = ((BigDecimal) arg27[4]).add(arg29);
						arg27[6] = ((BigDecimal) arg27[6]).subtract(arg29);
						break;
					}
				}
			}

			List arg40 = this.adjustBillDao.getMonthCost(startDate, endDate,
					Long.parseLong(tsId), arg26);

			for (contentType = 1; contentType <= 12; ++contentType) {
				arg41 = (Object[]) arr.get(contentType - 1);

				for (int j = 0; j < arg40.size(); ++j) {
					Object[] arg44 = (Object[]) arg40.get(j);
					String adjType = arg44[0].toString();
					if (contentType == Integer.parseInt(arg44[1].toString())) {
						arg29 = new BigDecimal(arg44[2].toString());
						if (adjType.equals("COLLECT_ABATE")
								|| adjType.equals("COO_ADD")
								|| adjType.equals("PAY_ADD")
								|| adjType.equals("PUR_BACK_ABATE")) {
							arg29 = (new BigDecimal(0)).subtract(arg29);
						}

						arg41[5] = ((BigDecimal) arg41[5]).add(arg29);
						arg41[6] = ((BigDecimal) arg41[6]).add(arg29);
						arg27[5] = ((BigDecimal) arg27[5]).add(arg29);
						arg27[6] = ((BigDecimal) arg27[6]).add(arg29);
					}
				}
			}

			String arg42 = request.getParameter("content_type");
			if (arg42 != null && arg42.equals("EXCEL")) {
				HashMap arg45 = new HashMap();
				arg45.put("list", arr);
				arg45.put("year", year);
				arg45.put("totalList", arg27);
				ProfitCountExcelView arg46 = new ProfitCountExcelView();
				return new ModelAndView(arg46, arg45);
			} else {
				ModelAndView arg43;
				if (arg42 != null && arg42.equals("PRINT")) {
					arg43 = new ModelAndView(this.profitCountPrintView);
					arg43.addObject("list", arr);
					arg43.addObject("totalList", arg27);
					arg43.addObject("year", year);
					return arg43;
				} else {
					arg43 = new ModelAndView(this.profitCountView);
					arg43.addObject("list", arr);
					arg43.addObject("totalList", arg27);
					arg43.addObject("year", year);
					arg43.addObject("tsId", tsId);
					arg43.addObject("currentYear", currentYear);
					arg43.addObject("tsList",
							PageHelper.getTallySetList(this.tallySetDao, arg26));
					return arg43;
				}
			}
		}
	}

	public ModelAndView handleAppList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else {
			try {
				EnterpriseInfo mapper = EncCommonHelper
						.getEnterpriseInfo(request);
				List json = PageHelper
						.parseBaList(this.bankAccountDao.getList("", ""),
								mapper, ub, 0L, 0L);
				ArrayList out = new ArrayList();

				for (int i = 0; i < json.size(); ++i) {
					HashMap item = new HashMap();
					BankAccount b = (BankAccount) json.get(i);
					String name = b.getBankName();
					if (b.getAccountName() != null
							&& !b.getAccountName().equals("")) {
						name = name + "(" + b.getAccountName() + ")";
					}

					item.put("id", Long.valueOf(b.getId()));
					item.put("name", name);
					out.add(item);
				}

				map.put("items", out);
				map.put("defa", Long.valueOf(ub.getUser().getDfBaId()));
				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg12) {
				map.put("status", "ERROR");
				map.put("errMsg", arg12.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg13 = new ObjectMapper();
		String arg14 = arg13.writeValueAsString(map);
		ServletOutputStream arg15 = response.getOutputStream();
		arg15.write(arg14.getBytes("utf-8"));
		arg15.flush();
		arg15.close();
		return null;
	}

	public ModelAndView handleAppAccoBala(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "BANK_COST")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("start_date");
				json = request.getParameter("end_date");
				String out = request.getParameter("ts_id");
				String at = request.getParameter("at");
				String initQuer = request.getParameter("init_quer");
				long tsId = 0L;
				if (out != null && !out.equals("")) {
					tsId = Long.parseLong(out);
				}

				Date startDate = null;
				Date endDate = null;
				Date monthStartDate = null;
				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				SimpleDateFormat sfs = new SimpleDateFormat("yyyy-MM");
				if (mapper != null && !mapper.equals("")) {
					startDate = sf.parse(mapper);
					monthStartDate = sf.parse(sfs.format(startDate) + "-01");
				}

				if (json != null && !json.equals("")) {
					endDate = sf.parse(EncCommonHelper.getNextDateStr(json,
							"yyyy-MM-dd"));
				}

				EnterpriseInfo ent = EncCommonHelper.getEnterpriseInfo(request);
				List bankAccountList = PageHelper.parseBaList(
						this.bankAccountDao.getList("Y", "Y"), ent, ub, 0L, 0L);
				List costList = this.bankAccountDetailDao.getBankAccountCost(
						startDate, endDate);
				ArrayList items = new ArrayList();

				for (int tmpList = 0; tmpList < bankAccountList.size(); ++tmpList) {
					BankAccount tsItems = (BankAccount) bankAccountList
							.get(tmpList);
					boolean i = true;
					if (i && tsId != 0L && tsItems.getTallySetId() != tsId) {
						i = false;
					}

					if (i && at != null && !at.equals("")) {
						if (at.equals("IS_TMP")
								&& tsItems.getIsTmp().equals("N")) {
							i = false;
						} else if (at.equals("NOT_TMP")
								&& tsItems.getIsTmp().equals("Y")) {
							i = false;
						}
					}

					if (i) {
						BigDecimal item = new BigDecimal(0);
						BankAccountBalance ts = this.bankAccountBalanceDao
								.getPreviousBalance(tsItems.getId(), startDate);
						if (ts != null) {
							item = ts.getCost();
						}

						BigDecimal preCost = this.bankAccountDetailDao.getCost(
								tsItems.getId(), monthStartDate, startDate);
						BigDecimal recCost = new BigDecimal(0);
						BigDecimal expCost = new BigDecimal(0);

						for (int staCost = 0; staCost < costList.size(); ++staCost) {
							Object[] endCost = (Object[]) costList.get(staCost);
							long difCost = Long
									.parseLong(endCost[0].toString());
							String item1 = endCost[1].toString();
							BigDecimal cost = new BigDecimal(
									endCost[2].toString());
							if (tsItems.getId() == difCost) {
								if (item1.equals("BUSINESS")) {
									recCost = recCost.add(cost);
								} else if (item1.equals("INCOME")) {
									recCost = recCost.add(cost);
								} else if (item1.equals("LOAN_IN")) {
									recCost = recCost.add(cost);
								} else if (item1.equals("TRANSFER_IN")) {
									recCost = recCost.add(cost);
								} else if (item1.equals("PURCHASE")) {
									expCost = expCost.add(cost);
								} else if (item1.equals("COOPER")) {
									expCost = expCost.add(cost);
								} else if (item1.equals("FEE")) {
									expCost = expCost.add(cost);
								} else if (item1.equals("LOAN_OUT")) {
									expCost = expCost.add(cost);
								} else {
									if (!item1.equals("TRANSFER_OUT")) {
										throw new Exception("finance type "
												+ item1 + " not supported!");
									}

									expCost = expCost.add(cost);
								}
							}
						}

						BigDecimal arg43 = item.add(preCost);
						BigDecimal arg44 = arg43.add(recCost).subtract(expCost);
						BigDecimal arg45 = arg44.subtract(arg43);
						String baName = tsItems.getBankName();
						if (tsItems.getAccountName() != null
								&& !tsItems.getAccountName().equals("")) {
							baName = baName + "(" + tsItems.getAccountName()
									+ ")";
						}

						HashMap arg46 = new HashMap();
						arg46.put("baId", Long.valueOf(tsItems.getId()));
						arg46.put("baName", baName);
						arg46.put("starCost", arg43);
						arg46.put("endCost", arg44);
						arg46.put("diffCost", arg45);
						arg46.put("receCost", recCost);
						arg46.put("expeCost", expCost);
						items.add(arg46);
					}
				}

				map.put("items", items);
				if (initQuer != null && initQuer.equals("Y")) {
					List arg38 = PageHelper.getTallySetList(this.tallySetDao,
							ub);
					ArrayList arg39 = new ArrayList();

					for (int arg40 = 0; arg40 < arg38.size(); ++arg40) {
						HashMap arg41 = new HashMap();
						TallySet arg42 = (TallySet) arg38.get(arg40);
						arg41.put("id", Long.valueOf(arg42.getId()));
						arg41.put("name", arg42.getTitle());
						arg39.add(arg41);
					}

					map.put("tsItems", arg39);
				}

				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg35) {
				map.put("status", "ERROR");
				map.put("errMsg", arg35.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg36 = new ObjectMapper();
		json = arg36.writeValueAsString(map);
		ServletOutputStream arg37 = response.getOutputStream();
		arg37.write(json.getBytes("utf-8"));
		arg37.flush();
		arg37.close();
		return null;
	}

	public ModelAndView handleAppAccoDeta(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HashMap map = new HashMap();
		UserStatus s = EncInterceptorHelper.checkAppUserSignon(request);
		UserBean ub = s.getUserBean();
		String json;
		if (ub == null) {
			map.put("status", "NO_LOGIN");
			map.put("errMsg", "");
		} else if (!EncCommonHelper.checkPrivilege(request, "BANK_COST")) {
			map.put("status", "ERROR");
			map.put("errMsg", "您还没有此功能的使用权限，请确认返回！");
		} else {
			try {
				String mapper = request.getParameter("ba_id");
				json = request.getParameter("start_date");
				String out = request.getParameter("end_date");
				String showPrev = request.getParameter("show_prev");
				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				Date startDate = null;
				if (json != null && !json.equals("")) {
					startDate = sf.parse(json);
				}

				Date endDate = null;
				if (out != null && !out.equals("")) {
					endDate = sf.parse(EncCommonHelper.getNextDateStr(out,
							"yyyy-MM-dd"));
				}

				BankAccount ba = (BankAccount) this.bankAccountBalanceDao.get(
						BankAccount.class, Long.parseLong(mapper));
				int total = 0;
				BigDecimal receCost = new BigDecimal(0);
				BigDecimal expeCost = new BigDecimal(0);
				List list = this.bankAccountDetailDao.getAppDetaCoun(
						ba.getId(), startDate, endDate);

				int perPageNum;
				for (perPageNum = 0; perPageNum < list.size(); ++perPageNum) {
					Object[] pageno = (Object[]) list.get(perPageNum);
					if (pageno[0] != null) {
						total += Integer.parseInt(pageno[1].toString());
						if (((String) pageno[0]).equals("R")) {
							receCost = receCost.add((BigDecimal) pageno[2]);
						} else {
							expeCost = expeCost.add((BigDecimal) pageno[2]);
						}
					}
				}

				map.put("baName", ba.getBankName());
				map.put("receCost", receCost);
				map.put("expeCost", expeCost);
				map.put("total", Integer.valueOf(total));
				perPageNum = EncCommonHelper.getPageSize(request);
				int arg26 = EncCommonHelper.getCurrentPageIndex(request, total,
						perPageNum);
				if (total > arg26 * perPageNum) {
					map.put("more", "Y");
				} else {
					map.put("more", "N");
				}

				if (showPrev != null && showPrev.equals("Y")) {
					list = this.bankAccountDetailDao.getAppDetaList(ba.getId(),
							startDate, endDate, 0, arg26 * perPageNum);
				} else {
					list = this.bankAccountDetailDao.getAppDetaList(ba.getId(),
							startDate, endDate, (arg26 - 1) * perPageNum,
							perPageNum);
				}

				ArrayList items = new ArrayList();

				for (int i = 0; i < list.size(); ++i) {
					HashMap item = new HashMap();
					BankAccountDetail b = (BankAccountDetail) list.get(i);
					item.put("date", sf.format(b.getBillDate()));
					item.put("cost", b.getCost());
					item.put("billCode", b.getBillCode());
					item.put("billType", b.getBillType());
					item.put("mark", PageHelper.parseNull(b.getMark()));
					item.put("mngName", b.getManagerName());
					item.put("billId", Long.valueOf(b.getBillId()));
					item.put("rcType", b.getRcType());
					item.put("finaType", b.getFinanceType());
					item.put("costType", b.getCostType());
					items.add(item);
				}

				map.put("items", items);
				map.put("status", "OK");
				map.put("errMsg", "");
			} catch (Exception arg23) {
				map.put("status", "ERROR");
				map.put("errMsg", arg23.toString());
			}
		}

		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		ObjectMapper arg24 = new ObjectMapper();
		json = arg24.writeValueAsString(map);
		ServletOutputStream arg25 = response.getOutputStream();
		arg25.write(json.getBytes("utf-8"));
		arg25.flush();
		arg25.close();
		return null;
	}

	public String getListView() {
		return this.listView;
	}

	public void setListView(String listView) {
		this.listView = listView;
	}

	public BankAccountDao getBankAccountDao() {
		return this.bankAccountDao;
	}

	public void setBankAccountDao(BankAccountDao bankAccountDao) {
		this.bankAccountDao = bankAccountDao;
	}

	public TallySetDao getTallySetDao() {
		return this.tallySetDao;
	}

	public void setTallySetDao(TallySetDao tallySetDao) {
		this.tallySetDao = tallySetDao;
	}

	public String getBalanceListView() {
		return this.balanceListView;
	}

	public void setBalanceListView(String balanceListView) {
		this.balanceListView = balanceListView;
	}

	public BankAccountBalanceDao getBankAccountBalanceDao() {
		return this.bankAccountBalanceDao;
	}

	public void setBankAccountBalanceDao(
			BankAccountBalanceDao bankAccountBalanceDao) {
		this.bankAccountBalanceDao = bankAccountBalanceDao;
	}

	public BankAccountDetailDao getBankAccountDetailDao() {
		return this.bankAccountDetailDao;
	}

	public void setBankAccountDetailDao(
			BankAccountDetailDao bankAccountDetailDao) {
		this.bankAccountDetailDao = bankAccountDetailDao;
	}

	public String getDetailListView() {
		return this.detailListView;
	}

	public void setDetailListView(String detailListView) {
		this.detailListView = detailListView;
	}

	public String getDetailPrintView() {
		return this.detailPrintView;
	}

	public void setDetailPrintView(String detailPrintView) {
		this.detailPrintView = detailPrintView;
	}

	public String getProfitSearchView() {
		return this.profitSearchView;
	}

	public void setProfitSearchView(String profitSearchView) {
		this.profitSearchView = profitSearchView;
	}

	public FeeTypeDao getFeeTypeDao() {
		return this.feeTypeDao;
	}

	public void setFeeTypeDao(FeeTypeDao feeTypeDao) {
		this.feeTypeDao = feeTypeDao;
	}

	public IncomeTypeDao getIncomeTypeDao() {
		return this.incomeTypeDao;
	}

	public void setIncomeTypeDao(IncomeTypeDao incomeTypeDao) {
		this.incomeTypeDao = incomeTypeDao;
	}

	public ReceiveBillDao getReceiveBillDao() {
		return this.receiveBillDao;
	}

	public void setReceiveBillDao(ReceiveBillDao receiveBillDao) {
		this.receiveBillDao = receiveBillDao;
	}

	public PayBillDao getPayBillDao() {
		return this.payBillDao;
	}

	public void setPayBillDao(PayBillDao payBillDao) {
		this.payBillDao = payBillDao;
	}
}